from toee import *
from utilities import *
from scripts import *
from council import *
from py00439script_daemon import record_time_stamp, get_v, set_v, npc_set, npc_unset, npc_get, tsc, within_rect_by_corners

def san_dialog( attachee, triggerer ):
	attachee.turn_towards(triggerer)
	if (game.leader.reputation_has(32) == 1 or game.leader.reputation_has(30) == 1 or game.leader.reputation_has(29) == 1):
		attachee.float_line(11004,triggerer)
	elif ((game.quests[3].state == qs_completed) or (game.quests[4].state == qs_completed)):
		triggerer.begin_dialog( attachee, 20 )
	elif ((attachee.has_met( triggerer )) or (game.quests[3].state == qs_accepted) or (game.quests[4].state == qs_accepted)):
		triggerer.begin_dialog( attachee, 10 )
	else:
		triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT

def san_dying( attachee, triggerer ):
	game.global_vars[23] = game.global_vars[23] + 1
	if (game.global_vars[23] >= 2):
		game.party[0].reputation_add( 1 )
	if game.leader.reputation_has(29) == 1:
		set_v(439,  get_v(439) + 1 )
	return RUN_DEFAULT


## THIS IS DEFAULT SCRIPT TO GET TWO WEAPON FIGHTERS TO USE TWO WEAPONS (this may not be needed)

def san_heartbeat( attachee, triggerer ):
	if (game.combat_is_active()):
		return RUN_DEFAULT
	if (attachee.name == 14238 and (not attachee.has_wielded(4099) or not attachee.has_wielded(4100))):
		attachee.item_wield_best_all()
		attachee.item_wield_best_all()
		game.new_sid = 0
	if (attachee.name == 14336 and attachee.item_find(4058) != OBJ_HANDLE_NULL):
		itemA = attachee.item_find(4058)
		itemA.destroy()
		create_item_in_inventory( 4126, attachee )
	if (attachee.name == 14336 and (not attachee.has_wielded(4081) or not attachee.has_wielded(4126))):
		attachee.item_wield_best_all()
		attachee.item_wield_best_all()
		game.new_sid = 0
	if (attachee.name == 14357 and attachee.item_find(4087) != OBJ_HANDLE_NULL):
		itemA = attachee.item_find(4087)
		itemA.destroy()
		itemA = attachee.item_find(5004)
		itemA.destroy()
	if (attachee.name == 14357 and (not attachee.has_wielded(4156) or not attachee.has_wielded(4159))):
		attachee.item_wield_best_all()
		attachee.item_wield_best_all()
		game.new_sid = 0
	if (attachee.name == 14747 and (not attachee.has_wielded(4040) or not attachee.has_wielded(4159))):
		attachee.item_wield_best_all()
		attachee.item_wield_best_all()
		game.new_sid = 0
	return RUN_DEFAULT


## THIS IS DEFAULT SCRIPT TO GET TWO WEAPON FIGHTERS TO USE TWO WEAPONS (this is needed)

def san_enter_combat( attachee, triggerer ):
	if (attachee.name == 14238 and (not attachee.has_wielded(4099) or not attachee.has_wielded(4100))):
		attachee.item_wield_best_all()
		game.new_sid = 0
	if (attachee.name == 14336 and (not attachee.has_wielded(4081) or not attachee.has_wielded(4126))):
		attachee.item_wield_best_all()
		game.new_sid = 0
	if (attachee.name == 14357 and (not attachee.has_wielded(4156) or not attachee.has_wielded(4159))):
		attachee.item_wield_best_all()
		game.new_sid = 0
	if (attachee.name == 14747 and (not attachee.has_wielded(4040) or not attachee.has_wielded(4159))):
		attachee.item_wield_best_all()
		game.new_sid = 0
	return RUN_DEFAULT

def san_start_combat( attachee, triggerer ):
	if (attachee.name == 14238 and (not attachee.has_wielded(4099) or not attachee.has_wielded(4100))):
		attachee.item_wield_best_all()
#		game.new_sid = 0
	if (attachee.name == 14336 and (not attachee.has_wielded(4081) or not attachee.has_wielded(4126))):
		attachee.item_wield_best_all()
		attachee.item_wield_best_all()
#		game.new_sid = 0
	if (attachee.name == 14357 and (not attachee.has_wielded(4156) or not attachee.has_wielded(4159))):
		attachee.item_wield_best_all()
#		game.new_sid = 0
	if (attachee.name == 14747 and (not attachee.has_wielded(4040) or not attachee.has_wielded(4159))):
		attachee.item_wield_best_all()

## ALSO, THIS IS USED FOR BREAK FREE
	while(attachee.item_find(8903) != OBJ_HANDLE_NULL):
		attachee.item_find(8903).destroy()
	if (attachee.d20_query(Q_Is_BreakFree_Possible)):
		create_item_in_inventory( 8903, attachee )
##		attachee.d20_send_signal(S_BreakFree)
	return RUN_DEFAULT

def	san_disband( attachee, triggerer ):
	for pc in game.party:
		attachee.ai_shitlist_remove( pc )
		attachee.reaction_set( pc, 50 )
	return RUN_DEFAULT